package cbs.demo.graal;

import com.oracle.svm.core.annotate.AutomaticFeature;
import org.graalvm.nativeimage.hosted.Feature;
import org.graalvm.nativeimage.hosted.RuntimeReflection;

/**
 * 这个类中的代码是在NativeImage编译的时候运行的
 */
@AutomaticFeature
public class NativeImageGen implements Feature {
    //这里我们直接写死了这个类名,实际项目中可以根据配置文件中配置的包名,扫描包下所有类进行注册
    private String className = "cbs.demo.domain.Patient";

    @Override
    public void beforeAnalysis(BeforeAnalysisAccess access) {
        try {
            var loader = Thread.currentThread().getContextClassLoader();
            var clazz = loader.loadClass(className);
            //注册该类
//            RuntimeReflection.register(clazz);
        } catch (Throwable t) {
            t.printStackTrace();
        }
    }
}
